﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using StockManagement.Helper;
using System.Data;
using StockManagement.Models;

namespace StockManagement.Model
{
    public class Material
    {
        public Guid MaterialID { get; private set; }
        public string Name { get; set; }
        public EnumMaterialType MaterialType { get; set; }
        public string MaterialCode { get; set; }
        public Guid VendorID { get; set; }
        public double Rate { get; set; }
        public int Quantity { get; set; }
        public DateTime Date { get; set; }
        public double Vat { get; set; }
        public string Purchaser { get; set; }
        
        public Material()
        {
            MaterialID = Guid.NewGuid();
            Name = string.Empty;
            MaterialType = EnumMaterialType.Trading;
            MaterialCode = string.Empty;
            VendorID = Guid.Empty;
            Rate = 0;
            Quantity = 0;
            Date = DateTime.Today;
            Vat = 0;
            Purchaser = string.Empty;
        }

        public Material(DataRow materialrow)
        {
            MaterialID = (Guid)materialrow["MaterialID"];
            Name = materialrow["Name"].ToString();
            MaterialType = DataHelper.GetMaterialType(materialrow["MaterialType"].ToString());
            MaterialCode = materialrow["MaterialCode"].ToString();
            VendorID = (Guid)materialrow["VendorID"];
            Date = (DateTime)materialrow["Date"];
            Rate = int.Parse(materialrow["Rate"].ToString());
            Quantity = int.Parse(materialrow["Quantity"].ToString());
            Vat = double.Parse(materialrow["Vat"].ToString());
            Purchaser = materialrow["Purchaser"].ToString();
        }

    }
}
